home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / system-tools-backends-2.0 / scripts / Utils / Backend.pm next >
Encoding:
Perl POD Document  |  2009-04-09  |  4.3 KB  |  168 lines

  1. #!/usr/bin/perl
  2. #-*- Mode: perl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  3.  
  4. # Common stuff for the ximian-setup-tools backends.
  5. #
  6. # Copyright (C) 2000-2001 Ximian, Inc.
  7. #
  8. # Authors: Hans Petter Jansson <hpj@ximian.com>
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU Library General Public License as published
  12. # by the Free Software Foundation; either version 2 of the License, or
  13. # (at your option) any later version.
  14. #
  15. # This program is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. # GNU Library General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU Library General Public License
  21. # along with this program; if not, write to the Free Software
  22. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
  23.  
  24. package Utils::Backend;
  25.  
  26. use Utils::Report;
  27. use Utils::Platform;
  28.  
  29. our $DBUS_PREFIX = "org.freedesktop.SystemToolsBackends";
  30. our $DBUS_PATH   = "/org/freedesktop/SystemToolsBackends";
  31. our $localstatedir;
  32. our $tool;
  33.  
  34. # --- Operation modifying variables --- #
  35.  
  36. # if $exit_code is provided (ne undef), exit with that code at the end.
  37. sub print_usage
  38. {
  39.   my ($tool, $exit_code) = @_;
  40.  
  41.   my $usage_text =<< "end_of_usage_text;";
  42.         NOTE: You should not be running this directly, this is only
  43.               recomended for debugging purposes.
  44.  
  45.        Usage: SystemToolsBackends.pl options
  46.  
  47.      Options:
  48.  
  49.            -h --help  Show help options.
  50.  
  51.           --platform  <name-ver>  Overrides the detection of your platform\'s
  52.                       name and version, e.g. redhat-6.2. Use with care.
  53.  
  54.             --module  <module> Defines the configuration module to load:
  55.                       GroupsConfig, HostsConfig, IfacesConfig, NFSConfig,
  56.                       NTPConfig, ServicesConfig, SMBConfig, TimeConfig
  57.                       or UsersConfig.
  58.  
  59.         -v --verbose  Prints human-readable diagnostic messages to standard
  60.                       error.
  61.  
  62.   --disable-shutdown  Disable default shutdown timeout of 180 seconds.
  63.  
  64.     --list-platforms  List available platforms.
  65.  
  66. end_of_usage_text;
  67.  
  68.   print STDERR $usage_text;
  69.  
  70.   exit $exit_code if $exit_code ne undef;
  71. }
  72.  
  73. sub print_platform_list
  74. {
  75.   my ($platforms) = &Utils::Platform::get_platform_info ();
  76.  
  77.   foreach $platform (keys %$platforms)
  78.   {
  79.     my $value = $$platforms{$platform};
  80.     my $desc = join (" ", @$value);
  81.  
  82.     printf ("%s\t- %s\n", $platform, $desc);
  83.   }
  84.  
  85.   exit 0;
  86. }
  87.  
  88. # --- Initialization and finalization --- #
  89.  
  90. sub set_with_param
  91. {
  92.   my ($tool, $arg_name, $value) = @_;
  93.  
  94.   if ($$tool{$arg_name} ne "")
  95.   {
  96.     print STDERR "Error: You may specify --$arg_name only once.\n\n";
  97.     &print_usage ($tool, 1);
  98.   }
  99.   
  100.   if ($value eq "")
  101.   {
  102.     print STDERR "Error: You must specify an argument to the --$arg_name option.\n\n";
  103.     &print_usage ($tool, 1);
  104.   }
  105.   
  106.   $$tool{$arg_name} = $value;
  107. }
  108.  
  109. sub set_disable_shutdown
  110. {
  111.   my ($tool) = @_;
  112.   &set_with_param ($tool, "no-shutdown", 1);
  113. }
  114.  
  115. sub set_module
  116. {
  117.   my ($tool, $module) = @_;
  118.   &set_with_param ($tool, "module", "$module.pm");
  119. }
  120.  
  121. sub set_prefix
  122. {
  123.   my ($tool, $prefix) = @_;
  124.   
  125.   &set_with_param ($tool, "prefix", $prefix);
  126.   $gst_prefix = $prefix;
  127. }
  128.  
  129. sub set_dist
  130. {
  131.   my ($tool, $dist) = @_;
  132.   &set_with_param ($tool, "platform", $dist);
  133. }
  134.  
  135. sub init
  136. {
  137.   my (@args) = @_;
  138.   my ($arg);
  139.  
  140.   # Set the output autoflush.
  141.   $old_fh = select (STDOUT); $| = 1; select ($old_fh);
  142.   $old_fh = select (STDERR); $| = 1; select ($old_fh);
  143.  
  144.   # Parse arguments.
  145.   while ($arg = shift (@args))
  146.   {
  147.     if    ($arg eq "--help"      || $arg eq "-h") { &print_usage   (\%tool, 0); }
  148.     elsif ($arg eq "--module"    || $arg eq "-m") { &set_module    (\%tool, shift @args); }
  149.     elsif ($arg eq "--platform")                  { &set_dist      (\%tool, shift @args); }
  150.     elsif ($arg eq "--disable-shutdown")          { &set_disable_shutdown (\%tool); }
  151.     elsif ($arg eq "--verbose"   || $arg eq "-v") { &set_with_param (\%tool, "do_verbose", 1); }
  152.     elsif ($arg eq "--list-platforms")            { &print_platform_list (\%tool) }
  153.     else
  154.     {
  155.       print STDERR "Error: Unrecognized option '$arg'.\n\n";
  156.       &print_usage (\%tool, 1);
  157.     }
  158.   }
  159.  
  160.   # Set up subsystems.
  161.   &Utils::Report::begin ();
  162.   &Utils::Platform::get_system ();
  163.  
  164.   return \%tool;
  165. }
  166.  
  167. 1;
  168.